<?php

namespace app\adminapi\lists\system;

use adminmatrix\admin\annotation\Inject;
use adminmatrix\admin\lists\BaseListsData;
use app\adminapi\model\Admin\AdminRole;

class RoleLists extends BaseListsData
{
    #[Inject]
    protected AdminRole $model;

    protected function initialize()
    {
        // 确保 model 被初始化
        if (!isset($this->model)) {
            $this->model = new AdminRole();
        }
    }

    public function lists(): array|object
    {
        return $this->autoLimit($this->model)->with(['perms'])->withAttr('perms' , function($query){
            return $query->column('permission_id');
        })->select();
    }

    public function count(): int
    {
        return $this->model->count();
    }
}